﻿
@{
    ViewData["Title"] = "供货商";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <fieldset class="table-search-fieldset">
                <legend>搜索信息</legend>
                <div style="margin: 10px 10px 10px 10px">
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">供货商编号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="PPID" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">供货商名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="PPName" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">公司名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="PPCompany" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">联系电话</label>
                                <div class="layui-inline">
                                    <label class="layui-form-label">公司名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="PPTel" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </div>
            </fieldset>

            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                </div>
            </script>

            <table class="layui-hide" id="StockTable" lay-filter="currentTableFilter"></table>

            <script type="text/html" id="currentTableBar">
                <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
            </script>
        </div>
    </div>

    <script>
        layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function () {
            var laydate = layui.laydate //日期
                , form = layui.form
                , laypage = layui.laypage //分页
                , layer = layui.layer //弹层
                , table = layui.table
                , upload = layui.upload //上传
                , element = layui.element //元素操作
                , slider = layui.slider; //滑块

            laydate.render({
                elem: '#stockDate'// 下单时间

            });
            laydate.render({
                elem: '#stockInDate' //预计交货时间
            });

            table.render({
                elem: '#StockTable',
                url: '/ProductLend/ProductLend/GetPageListData',
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }]
                , cols: [[
                    { field: 'PPID', title: '供货商编号', width: 180, sort: true, fixed: 'left' }
                    , { field: 'PPName', title: '供货商名称', width: 180, sort: true, fixed: 'left' }
                    , { field: 'PPCompany', title: '公司名称', width: 200, fixed: 'left' }
                    , { field: 'PPMan', title: '联系人', width: 180, fixed: 'left' }
                    , { field: 'PPTel', title: '联系电话', width: 180, fixed: 'left' }
                    , { field: 'PPAddress', title: '地址', width: 180, fixed: 'left' }
                    , { field: 'PPFax', title: '传真', width: 180, fixed: 'left' }
                    , { field: 'PPEmail', title: 'Email', width: 180, fixed: 'left' }
                    , { field: 'PPUrl', title: '网址', width: 180, fixed: 'left' }
                    , { field: 'PPDesc', title: '备注', width: 200, }
                    , { title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center" }
                ]],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 10,
                page: true,
                skin: 'line'
            });

            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                 var applet_Stocks = {};
                applet_Stocks = data.field;
                //执行搜索重载
                table.reload('goodscatID', {
                    page: {
                        curr: 1
                    }
                    , where: {
                        searchParams: applet_Stocks
                    }
                }, 'data');
                $.ajax({
                    type: 'post',
                    url: '/Stock/Stock/GetData',
                    data: applet_Stocks,
                    dataType: "json",
                    success: function (data) {
                        debugger
                    }, error: function (err) {
                        layer.alert(err.responseText);
                    }
                })
                return false;
            });

            /**
             * toolbar监听事件
             */
            table.on('toolbar(currentTableFilter)', function (obj) {
                if (obj.event === 'add') {  // 监听添加操作
                    var index = layer.open({
                        title: '添加采购单',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['100%', '100%'],
                        content: '/Stock/Stock/AddStock',
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                        table.reload('StockTable', { page: { curr: index } });
                    });
                } else if (obj.event === 'delete') {  // 监听删除操作
                    var checkStatus = table.checkStatus('StockTable')
                        , data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                }
            });

            //监听表格复选框选择
            table.on('checkbox(currentTableFilter)', function (obj) {
                console.log("复选框选中的值=》" + obj);
            });

            table.on('tool(currentTableFilter)', function (obj) {
                var data = obj.data;
                var stockID = obj.data.stockID;
                if (obj.event === 'edit') {
                    var index = layer.open({
                        title: '编辑采购单',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['100%', '100%'],
                        content: '/Stock/Stock/UpdateStock?stockID=' + stockID,
                    });
                    $(window).on("resize", function () {
                        table.reload('StockTable', { page: { curr: index } });
                    });
                }
                else if (obj.event === 'delete') {
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            type: 'post',
                            url: '/Stock/Stock/RemoveStockInfor',
                            data: { stockID: stockID },
                            dataType: "json",
                            success: function (data) {
                                layer.msg(data.info, {
                                    icon: 1
                                }, function () {
                                        table.reload('StockTable', { page: { curr: index } });
                                });
                                return false;
                            },
                            error: function (err) {
                                layer.alert(err.responseText);
                            }
                        })
                    });
                }
            });
        });
    </script>

</body>